layui.use(['jquery','layer','table','form','laydate'],function() {
    var $ = layui.jquery;
    var layer = layui.layer;
    var table = layui.table;
    var form = layui.form;
    var laydate = layui.laydate;

    laydate.render({
        elem: '#createDate',
        type: 'datetime',
        trigger: 'click'
    })

    //刷新
    refresh = function refresh(){
        location.reload();
    }
    //返回
    $('#goBack').click(function () {
        parent.tabParentChange(3);
    })
    $(document).click(function () {
        parent.$('.rightMenu').hide();
    });


    $('.layui-row').children('.layui-btn').click(function () {
        $(this).removeClass('layui-btn-primary').siblings().addClass('layui-btn-primary');
    });

    //点击不同的按钮展示不同的审核状态
    //已通过
    $("#reviewed").click(function () {
        $.ajax({
            url:"/applyRecord/getAuditLogByType",
            data:{'type' : 2},
            type:"post",
            dataType:"json",
            success:function (data) {
                demoTable(data.data);
            }
        })
    });
    //已驳回
    $("#rejected").click(function () {
        $.ajax({
            url:"/applyRecord/getAuditLogByType",
            data:{'type' : 3},
            type:"post",
            dataType:"json",
            success:function (data) {
                demoTable(data.data);
            }
        })
    });

    getTable('','','');

    function getTable(createDate,account,nickname){
        var param={
            'createDate':createDate,
            'account':account,
            'nickname':nickname
        }
        $.ajax({
            url:"/applyRecord/getAuditLog",
            data:param,
            type:"post",
            dataType:"json",
            success:function (data) {
                demoTable(data.data);
            }
        })
    }

    //模糊查询
    search=function search(){
        var createDate=$("input[name=createDate]").val();
        var account=$("input[name=account]").val();
        var nickname=$("input[name=nickname]").val();
        getTable(createDate,account,nickname);
    }

    //表格
    function demoTable(data){
        table.render({
            elem:'#demoTable',
            title:"委托书",
            data:data,
            toolbar:'#button_ids',
            limit:10,
            page:{
                layout:['count','prev','page','next','limit','skip','refresh'],
                limits:[10,20,30],
                first:"首页",
                last:"尾页",
            },
            cols:[[
                {type:'checkbox'},
                {title: '序号',align:'center', templet: function (data) {
                        return data.LAY_INDEX;
                    }},
                {field:"nickname",title:"用户姓名",align:'center'},
                {field:"account",title:"用户账号",align:'center'},
                {field:"userName",title:"审核人",align:'center'},
                {field:"createDate",title:"审核时间",align:'center'},
                {field:"remark",title:"备注",align:'center'},
                {field:"type",title:"审核状态",align:'center',templet:function(data){
                        if(data.type == 2){
                            return "已通过"
                        }else if(data.type == 3){
                            return "已驳回"
                        }
                    }},
                {field:'',title:"操作",align:'center',toolbar:'#button_caozuo'}
            ]]
        })
    }

    //删除
    table.on('tool(demoTable)',function (obj) {
        var event = obj.event;
        if(event == "deleteTable"){
            layer.confirm('确认要删除吗?', {icon: 3, title:'提示'}, function(index){
                $.ajax({
                    url:"/applyRecord/delAuditLog",
                    data:{'auditLogId':obj.data.auditLogId},
                    type:"post",
                    dataType:"json",
                    success:function (data) {
                        layer.msg("已删除！！！");
                        getTable('','','');
                    }
                })
                layer.close(index);
            })
        }
    })

})